/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Hogar;

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class Falarma extends Canvas implements CommandListener{
//Declaración de variables
private SelectAlarm temp;
private Ticker tick;
private Command atras, aceptar;
private int[][] coordTemp;
private boolean[] estAlarma;
private Image planta, conectada, noConectada;
private int[] coordRect;
private Hogar midlet;
public Falarma(Hogar midlet){
this.midlet = midlet; //Guardo la referencia del MIDlet
temp = new SelectAlarm(midlet);
coordRect = new int[4];
planta = midlet.edificio.getPlanta();
tick = new Ticker("Alarma");
//Creo los elementos del formulario principal
atras = new Command("Atras",Command.BACK,1);
aceptar = new Command("Aceptar",Command.OK,1);
//Inserto los elementos en el formulario principal
this.setTicker(tick);
this.addCommand(atras);
this.setCommandListener(this);
try{
conectada = Image.createImage("/conec.png");
noConectada = Image.createImage("/nocon.png");
}catch (Exception e){
System.out.println(e);
}
}
public void paint(Graphics g){
estAlarma = midlet.edificio.getEstAlarma();
g.drawImage(planta,0,0,Graphics.TOP|Graphics.LEFT);
dibujarAlarmas(g);
g.setColor(255,0,0);
g.drawRect(coordRect[0],coordRect[1],coordRect[2],coordRect[3]);
}
public void dibujarAlarmas(Graphics g){
g.setColor(255,255,255);
for (int i=0;i<midlet.edificio.getNumHabitaciones();i++){
if (estAlarma[i]){
g.drawImage(conectada,coordTemp[i][0],coordTemp[i][1],
Graphics.TOP|Graphics.LEFT);
}else g.drawImage(noConectada,coordTemp[i][0],coordTemp[i][1],
Graphics.TOP|Graphics.LEFT);
}
}
public void commandAction(Command c, Displayable d){
if (c == atras)
midlet.verOpciones();
}
public void keyPressed(int codigo){
int ncod = getGameAction(codigo);
int[] ncoord;
switch (ncod){
case Canvas.FIRE:{
temp.setEstado(midlet.edificio.getAlarmaHab());
midlet.pantalla.setCurrent(temp);
break;
}
case Canvas.UP:{
ncoord = midlet.edificio.mostrarPlanta(0);
for (int i=0;i<4;i++)
coordRect[i] = ncoord[i];
break;
}
case Canvas.DOWN:{
ncoord = midlet.edificio.mostrarPlanta(1);
for (int i=0;i<4;i++)
coordRect[i] = ncoord[i];
break;
}
case Canvas.RIGHT:{
ncoord = midlet.edificio.mostrarPlanta(2);
for (int i=0;i<4;i++)
coordRect[i] = ncoord[i];
break;
}
case Canvas.LEFT:{
ncoord = midlet.edificio.mostrarPlanta(3);
for (int i=0;i<4;i++)
coordRect[i] = ncoord[i];
break;
}
}
ncoord = null;
repaint();
}
public void setCoord(int[] c){
for (int i=0;i<midlet.edificio.getNumHabitaciones();i++)
coordRect[i] = c[i];
}
public void setInfo1(int[][] c){
coordTemp = c;
}
public void setInfo2(boolean[] est){
estAlarma = est;
}
}
